﻿using MVCReview.Models;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;

namespace MVCReview.Controllers
{
    public class HomeController : Controller
    {
        string UserName = "Jeremy";
        public ActionResult Index()
        {
            return View(ListStatic.Markers);
        }
        public ActionResult ShowMarker(int markerId)
        {
            MarkerViewModel model = new MarkerViewModel();
            //Where NEEDS FirstOrDefault() OR ToList() after
            model.Marker = ListStatic.Markers.Where(x => x.Id == markerId).FirstOrDefault();
            model.Name = UserName;
            return View(model);
        }
        public ActionResult EditMarker(int id)
        {
            Marker model = ListStatic.Markers.Find(x => x.Id == id);
            return View(model);
        }
        [HttpPost]
        public ActionResult EditMarker(Marker marker) 
        {
            foreach (Marker x in ListStatic.Markers)
            {
                if (x.Id == marker.Id)
                {
                    x.Color = marker.Color;
                    x.CapMaterial = marker.CapMaterial;
                    x.HasCap = marker.HasCap;
                }
            }
            return RedirectToAction("Index");
        }
        public ActionResult CreateMarker()
        {
            return View();
        }
        [HttpPost]
        public ActionResult CreateMarker(Marker marker)
        {
            marker.Id = ListStatic.Markers.Count + 1;
            ListStatic.Markers.Add(marker);
            return RedirectToAction("Index");
        }
        public ActionResult DeleteMarker(int id)
        {
            Marker tempMarker = ListStatic.Markers.Find(x => x.Id == id);
            ListStatic.Markers.Remove(tempMarker);

            return RedirectToAction("Index");
        }

        public ActionResult About()
        {

            return View();
        }

        public ActionResult Contact()
        {

            return View();
        }
    }
}